package edu.zut.main.ThreadTest;

public class SaleTicket {/**
 * 自动买车票
 */
public static void main(String[] args) {
    Tickets ts = new Tickets();
    sale s = new sale(ts);

    Thread thread1 = new Thread(s,"小郭");
    Thread thread2 = new Thread(s,"小李");
    Thread thread3 = new Thread(s,"小花");

    thread1.start();
    thread2.start();
    thread3.start();
    //sale s = new sale();
    //
    //Thread thread1 = new Thread(s,"小郭");
    //Thread thread2 = new Thread(s,"小李");
    //Thread thread3 = new Thread(s,"小花");
    //
    //thread1.start();
    //thread2.start();
    //thread3.start();
}
}
class sale implements Runnable{
    private Tickets ts;

    public sale(Tickets ts) {
        this.ts = ts;
    }
    //Tickets ts = new Tickets()

    @Override
    public void run() {
        while (true){
            if(ts.getTs()<=0){
                break;
            }else {
                ts.saleTs();
            }

        }

    }
}
class Tickets{
    private int ts = 10;

    public int getTs() {
        return ts;
    }
    public void saleTs(){
        System.out.println(Thread.currentThread().getName()+"卖出了第"+ ts-- +"张票");
    }
}
